<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends BaseController {
    public function index(){
        //////类目展示
        $root_group_id=M("admin")->join("__DEPARTMENT__ on __DEPARTMENT__.id=__ADMIN__.department_id",'left')->where("username='".session('admin')."'")->getField('root_group_id');
        $group_id=explode(',',$root_group_id);
        $root=M('root')->where("is_root=1 or is_root=2")
            ->order("sort")->select();
        $new_arr=array();
        foreach($root as $k=>$v){
            if($v['is_root']==1){
                $new_arr[]=$v;
                unset($root[$k]);
            }
        }
        foreach($new_arr as $k=>$v){
            foreach($root as $j=>$u){
                if($u['controller']==$v['controller']){
                    if(in_array($u['id'],$group_id) || session('type')==1){
                        $new_arr[$k]['child'][]=$u;
                        unset($root[$j]);
                    }
                }
            }
            if(count($new_arr[$k]['child'])==0){
                unset($new_arr[$k]);
            }
        }
        $this->assign('list',$new_arr);
        $this->display();
    }
}